package settings_api

import (
	"github.com/gin-gonic/gin"
	"muziai-server/global"
	"muziai-server/models/ctype"
	"muziai-server/utils/jwts"
	"muziai-server/utils/res"
)

func (SettingsApi) SettingInfoView(c *gin.Context) {

	name := c.Param("name")
	if name == "site_info" {
		res.OkWithData(c, global.Config.SiteInfo)
		return
	}
	var siteMap = map[string]any{
		"ai":       global.Config.AI,
		"wx_login": global.Config.WxLogin,
		"alipay":   global.Config.Aalipay,
		"email":    global.Config.Email,
		"sms":      global.Config.SMS,
		"ocr":      global.Config.Ocr,
	}
	//是否是管理员
	token := c.GetHeader("token")
	if token == "" {
		res.FailWithMsg(c, "未携带token")
		return
	}
	Claims, err := jwts.ParseToken(token)
	if err != nil {
		res.FailWithError(c, err)
		return
	}

	if Claims.Role != ctype.AdminRole {
		res.FailWithMsg(c, "权限错误")
		return
	}

	if name == "site_info" {
		res.OkWithData(c, global.Config.SiteInfo)
		return
	}
	data, ok := siteMap[name]
	if !ok {
		res.FailWithMsg(c, "不存在配置信息")
		return
	}
	res.OkWithData(c, data)

	return

}
